package vip.liux.contracts.security;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;

public class AnonymousUserDetails implements UserDetails {

    private final String principal;
    private final String credentials;

    public AnonymousUserDetails(String principal, String credentials) {
        this.principal = principal;
        this.credentials = credentials;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        // 匿名用户无权限
        return Collections.emptyList();
    }

    @Override
    public String getPassword() {
        return credentials;
    }

    @Override
    public String getUsername() {
        return principal;
    }
}
